import { Component, OnInit } from '@angular/core';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { HeroService } from './hero.service';


@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.less']
})
export class HeroesComponent implements OnInit {

  // selectedHero: Hero;
  // heroes = HEROES;
  heroes: Hero[];
  test: any;
  htmlEl = '<div><h2>html test</h2></div>';

  constructor(private heroService: HeroService) {
    console.info('heroService', heroService);

    this.test = 'test1';
    console.info('变量提升测试：' + this.test);

    this.test = 'test2';
    console.info('变量提升测试2：' + this.test);

  }

  ngOnInit() {
    console.info('ng init');
    this.getHeroes();
  }

  getHeroes(): void {
    this.heroService.getHeroes()
      .subscribe(heroes => this.heroes = heroes);
  }

  onMouseEnter(el): void {
    console.info('el', el);
  }
  // onSelect(hero: Hero): void {
  //   this.selectedHero = hero;
  // }
}
